草庐IT

Python Django 模板 : Iterate Through List

全部标签

c++ - 从gdb中模板类的成员函数打印静态变量

我有一个简单的模板类:namespacetest{template>classDB{public:staticDB&instance(){staticDB_instance;return_instance;}private:DB(){};DB(DBconst&){};voidoperator=(DBconst&){};Container_db_internal;};}当我在gdb中调试时,我想查看_db_internal容器,但不知道如何访问它。我试着用gdb写:p'test::DB>::instance()::_instance'._db_internal它给了我:Nosymbol.

c++ - 模板默认类型与默认值

此问题遵循previousone.案例一:默认类型以下程序无法编译并报告errorC2995:'Tfoo(void)':functiontemplatehasalreadybeendefined:#include#includetemplate::value>>Tfoo(){std::cout::value>>Tfoo(){std::cout();foo();}每个模板都由两个foo实例交替使用和忽略(SFINAE)。所以我假设编译器在某个时候看到:templateTfoo(){std::coutTfoo(){std::cout两个定义是一样的,错误有点可以理解。也许不太容易理解的是为

c++ - 模板函数中需要什么类型的迭代器?

我正在制作自己的基于计数排序的sort()算法。它对范围有限的正数进行排序。到目前为止,它适用于std::string和std::vector。原型(prototype)如下:templatevoidsortIntegers(ForwardIteratorstart,ForwardIteratorend)我的算法使用*iter=、++iter和copy=iter。来自http://www.cplusplus.com/reference/iterator/我确定我需要一个ForwardIterator或更好的。这是确定我的算法所需的最通用迭代器类型的正确方法吗?我不确定我是否应该尝试变得

c++ - 可变参数模板 initilizer_list 技巧

我在visualstudio2017RC上使用C++17编写了for_each_tuple,我对这种实现感到震惊。查看:templateconstexprautofor_each_tuple(fun_t&fun,tuple_t&&tuple){std::apply([&](auto&&...args){autol={(fun(std::forward(args)),0)...};},std::forward(tuple));}intmain(){autotup=std::make_tuple(1,2,3,4);for_each_tuple([](auto&arg){++arg;},tu

c++ - 如何使用通用模板函数来处理具有不同成员的对象?

我已经四处寻找解决方案了一段时间,但是,我可能不知道我要实现的目标的确切定义或语言语法,所以我决定发布。我有这样的某些对象/结构:structA{charmyChar;boolhasArray=false;};templatestructAA:publicA{hasArray=true;uint8_tmyArray[ARRAY_LEN];};我想创建一个通用函数,它可以接受这两种对象类型,并为派生的structAA执行常见工作和特定工作。类似于以下内容:templatevoidfunc(T(&m)){if(T.hasArray){//dosomeprocessingwithm.myAr

c++ - 如何与 "template using"定义的模板(别名)类成为 friend ?

类B想和每个人成为friendC.我正在努力寻找解决方法。只要我不添加有问题的行,下面是成功编译的完整代码。#includeusingnamespacestd;enumEN{EN1,EN2};templateclassC{public:C(){std::coutclassB{templateusingCT=C;//templatefriendclassCT;//ct;}};intmain(){B::test();return0;}这是我尝试过的(全部失败):-templatefriendclassC;templatefriendclassCT;templatefriendclassCT

C++错误没有匹配函数来调用静态模板方法

我试图从另一个类调用一个静态方法,但是当我运行它时,它抛出这个:PagedArray.cpp:21:37:error:nomatchingfunctionforcallto‘FileManager::loadPage(int&)’page=FileManager::loadPage(index);这是我尝试从中调用它的代码:分页数组.cpp#include"PagedArray.h"#include"../Entidades/FileManager.h"templateint*PagedArray::operator[](intindex){Page*page=nullptr;for(

c++ - 如何从通用模板 <typename T> 中提取 lambda 的返回类型和可变参数包

我想创建一个模板化类或函数,它接收一个lambda,并将它放在std::function内部Lambda可以有任意数量的输入参数[](inta,floatb,...)std::function应该对应于lambda的operator()的类型templatevoidgetLambda(Tt){//typedeflambda_traits::ret_typeRetType;??//typedeflambda_traits::param_tuple-->somehowbacktoparameterpackArgs...std::functionfun(t);}intmain(){intx=

c++ - 在模板类中编写友元函数声明的正确方法是什么?

我正在尝试编写自己的vector模板类,但在编写友元函数声明时遇到了一些问题。一开始我是这样写的:template>classvector{public:friendbooloperator==(constvector&,constvector&);};但是编译器报了一个警告,说我声明了一个非模板函数。所以我将好友声明更改为:template>classvector{public:templatefriendbooloperator==(constvector&,constvector&);};到目前为止一切都很好,但我认为仍然存在问题。如果我那样写,我就把所有operator==将两

c++ - 通过 CRTP 检测模板类继承的元函数

我有一个这样的界面:templateclassInterface{...}及其具体实现:templateclassConcrete:publicInterface,T>{...usingtype=typenameT;}我想要一个元函数来检查某个类型是否来自Interface。举个例子,假设接口(interface)只有一个模板参数(因此它不会生成子模板类):templateclassA{...}classB:publicA{...}在这种情况下,我可以使用:templatestructis_A{staticboolconstvalue=std::is_base,T>::value;}我